import org.sca.middle.cmpe.user.Security
import org.sca.middle.cmpe.user.SecurityFactory
import org.sca.middle.cmpe.dto.Fighter
import org.sca.middle.cmpe.db.FighterDAO
import com.google.appengine.api.datastore.Entity
import com.google.appengine.api.blobstore.BlobInfo
import com.google.appengine.api.blobstore.BlobKey
import org.sca.middle.cmpe.dto.FighterListItem
import org.sca.middle.cmpe.dto.Authorization
import org.sca.middle.cmpe.utils.MarshalUtils
import org.sca.middle.cmpe.common.*
import com.google.appengine.api.datastore.*
import static com.google.appengine.api.datastore.FetchOptions.Builder.*
import java.text.DateFormat
import org.sca.middle.cmpe.dto.ScaGroup
import org.sca.middle.cmpe.db.ScaGroupDAO
import org.sca.middle.cmpe.dto.AuthCategory
import org.sca.middle.cmpe.db.AuthCategoryDAO
import org.sca.middle.cmpe.dto.AuthType
import org.sca.middle.cmpe.db.AuthTypeDAO

// Add groups
def sgDAO = new ScaGroupDAO()
def scaGroup = new ScaGroup ()
scaGroup.groupName = "Afonlyn (Shire)"
scaGroup.groupLocation = "Constellation"
def scaGroupKey = sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Cúil Choluim (Shire)"
scaGroup.groupLocation = "Constellation"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Dragon's Vale (Shire)"
scaGroup.groupLocation = "Constellation"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Greyhope (Shire)"
scaGroup.groupLocation = "Constellation"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Mynydd Seren (Shire)"
scaGroup.groupLocation = "Constellation"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Narrental (Shire)"
scaGroup.groupLocation = "Constellation"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Qal`at Ja`far (Shire)"
scaGroup.groupLocation = "Constellation"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Rivenstar (Barony)"
scaGroup.groupLocation = "Constellation"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Riviere Constelle (Shire)"
scaGroup.groupLocation = "Constellation"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Shadowed Stars (Shire)"
scaGroup.groupLocation = "Constellation"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Steren Codha (Shire)"
scaGroup.groupLocation = "Constellation"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Sternfeld (Barony)"
scaGroup.groupLocation = "Constellation"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "White Waters (Barony)"
scaGroup.groupLocation = "Constellation"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Ayreton (Barony)"
scaGroup.groupLocation = "Midlands"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Foxvale (Canton of Ayreton)"
scaGroup.groupLocation = "Midlands"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Grey Gargoyles (Canton of Ayreton)"
scaGroup.groupLocation = "Midlands"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Rokkehealden (Canton of Ayreton)"
scaGroup.groupLocation = "Midlands"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Tree-Girt-Sea (Canton of Ayreton)"
scaGroup.groupLocation = "Midlands"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Vanished Wood (Canton of Ayreton)"
scaGroup.groupLocation = "Midlands"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Baile na Scolairi (Shire)"
scaGroup.groupLocation = "Midlands"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Blackhawk (Shire)"
scaGroup.groupLocation = "Midlands"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Carraig Ban (Barony)"
scaGroup.groupLocation = "Midlands"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Dark River (Shire)"
scaGroup.groupLocation = "Midlands"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Illiton (Barony)"
scaGroup.groupLocation = "Midlands"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Lochmorrow (Canton of Illiton)"
scaGroup.groupLocation = "Midlands"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Athelington (Incipient Canton of Illiton)"
scaGroup.groupLocation = "Midlands"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Ravenslake (Shire)"
scaGroup.groupLocation = "Midlands"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Saint Carol on the Moor (College)"
scaGroup.groupLocation = "Midlands"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Shattered Crystal (Barony)"
scaGroup.groupLocation = "Midlands"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Swordcliff (Shire)"
scaGroup.groupLocation = "Midlands"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Wurm Wald (Shire)"
scaGroup.groupLocation = "Midlands"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Black Rock Forge (Incipient Canton)"
scaGroup.groupLocation = "Midlands"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Runvidrstad (Incipient Shire)"
scaGroup.groupLocation = "Midlands"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Brendoken (Barony)"
scaGroup.groupLocation = "North Oaken"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Alderford (Canton of Brendoken)"
scaGroup.groupLocation = "North Oaken"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Gwyntarian (Canton of Brendoken)"
scaGroup.groupLocation = "North Oaken"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Thistle (Canton of Brendoken)"
scaGroup.groupLocation = "North Oaken"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Three Towers (Canton of Brendoken)"
scaGroup.groupLocation = "North Oaken"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Castell Gwent (Shire)"
scaGroup.groupLocation = "North Oaken"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Cleftlands (Barony)"
scaGroup.groupLocation = "North Oaken"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Eastwatch (Shire)"
scaGroup.groupLocation = "North Oaken"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Falcon's Quarry (Shire)"
scaGroup.groupLocation = "North Oaken"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Middle Marches (Barony)"
scaGroup.groupLocation = "North Oaken"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Dernehealde (Shire of Middle Marches)"
scaGroup.groupLocation = "North Oaken"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Gleann Iaruinn (Canton of Middle Marches)"
scaGroup.groupLocation = "North Oaken"
sgDAO.saveScaGroup(scaGroup)

def mugmortGroup = new ScaGroup ()
mugmortGroup.groupName = "Mugmort (Shire of Middle Marches)"
mugmortGroup.groupLocation = "North Oaken"
def mugmortGroupKey = sgDAO.saveScaGroup(mugmortGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Tirnewydd (Shire of Middle Marches)"
scaGroup.groupLocation = "North Oaken"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Oakford (Shire)"
scaGroup.groupLocation = "North Oaken"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Red Spears (Barony)"
scaGroup.groupLocation = "North Oaken"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Catteden (Canton of Red Spears)"
scaGroup.groupLocation = "North Oaken"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Hróðgeirsfjörðr (Canton of Red Spears)"
scaGroup.groupLocation = "North Oaken"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Marshes, Marche of the (Canton of Red Spears)"
scaGroup.groupLocation = "North Oaken"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Rivenvale (Shire)"
scaGroup.groupLocation = "North Oaken"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Altenberg (Shire)"
scaGroup.groupLocation = "Pentamere"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Andelcrag (Barony)"
scaGroup.groupLocation = "Pentamere"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Dun Traigh (Canton of Andelcrag)"
scaGroup.groupLocation = "Pentamere"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Nordheim (Canton of Andelcrag)"
scaGroup.groupLocation = "Pentamere"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Rimsholt (Canton of Andelcrag)"
scaGroup.groupLocation = "Pentamere"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Three Hills (Canton of Andelcrag)"
scaGroup.groupLocation = "Pentamere"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Three Walls (Canton of Andelcrag)"
scaGroup.groupLocation = "Pentamere"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Westmere (Canton of Andelcrag)"
scaGroup.groupLocation = "Pentamere"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Cynnabar (Barony)"
scaGroup.groupLocation = "Pentamere"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Donnershafen (Barony)"
scaGroup.groupLocation = "Pentamere"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Fearann na Criche (Shire)"
scaGroup.groupLocation = "Pentamere"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Northwoods (Barony)"
scaGroup.groupLocation = "Pentamere"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Ealdnordwuda (Canton of Northwoods)"
scaGroup.groupLocation = "Pentamere"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Hawkland Moor (Riding of Northwoods)"
scaGroup.groupLocation = "Pentamere"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Iron Oak (Incipient Canton of Northwoods)"
scaGroup.groupLocation = "Pentamere"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Wealdlake (Canton of Northwoods)"
scaGroup.groupLocation = "Pentamere"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Roaring Wastes (Barony)"
scaGroup.groupLocation = "Pentamere"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Brackendelve (Canton of Roaring Wastes)"
scaGroup.groupLocation = "Pentamere"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Starleaf Gate (Shire)"
scaGroup.groupLocation = "Pentamere"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Stormvale (Shire)"
scaGroup.groupLocation = "Pentamere"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Talonval (Shire)"
scaGroup.groupLocation = "Pentamere"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Aurea Ripae (Shire)"
scaGroup.groupLocation = "South Oaken"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Dragonsmark (Shire)"
scaGroup.groupLocation = "South Oaken"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Okenshield (Shire)"
scaGroup.groupLocation = "South Oaken"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Fenix (Barony)"
scaGroup.groupLocation = "South Oaken"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Flame (Barony)"
scaGroup.groupLocation = "South Oaken"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Flaming Gryphon (Barony)"
scaGroup.groupLocation = "South Oaken"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Havenholde (Canton of Flaming Gryphon)"
scaGroup.groupLocation = "South Oaken"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Hawkes Keye (Canton of Flaming Gryphon)"
scaGroup.groupLocation = "South Oaken"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Norborough (Canton of Flaming Gryphon)"
scaGroup.groupLocation = "South Oaken"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Unicorn (Canton of Flaming Gryphon)"
scaGroup.groupLocation = "South Oaken"
sgDAO.saveScaGroup(scaGroup)

scaGroup = new ScaGroup ()
scaGroup.groupName = "Winged Hills (Canton of Flaming Gryphon)"
scaGroup.groupLocation = "South Oaken"
sgDAO.saveScaGroup(scaGroup)


// Add authorization categories
def i1 = 0
def acatDAO = new AuthCategoryDAO ()
def acatArmoredCombat = new AuthCategory ()
acatArmoredCombat.description = "Armored Combat"
acatArmoredCombat.orderValue = ++i1
acatDAO.saveAuthCategory(acatArmoredCombat)

def acatCombatArchery = new AuthCategory ()
acatCombatArchery.description = "Combat Archery"
acatCombatArchery.orderValue = ++i1
acatDAO.saveAuthCategory(acatCombatArchery)

def acatSiege = new AuthCategory ()
acatSiege.description = "Siege"
acatSiege.orderValue = ++i1
acatDAO.saveAuthCategory(acatSiege)

def acatRapier = new AuthCategory ()
acatRapier.description = "Rapier"
acatRapier.orderValue = ++i1
acatDAO.saveAuthCategory(acatRapier)

def acatYouth = new AuthCategory ()
acatYouth.description = "Youth"
acatYouth.orderValue = ++i1
acatDAO.saveAuthCategory(acatYouth)

def acatEquestrian = new AuthCategory ()
acatEquestrian.description = "Equestrian"
acatEquestrian.orderValue = ++i1
acatDAO.saveAuthCategory(acatEquestrian)

def acatTargetArchery = new AuthCategory ()
acatTargetArchery.description = "Target Archery"
acatTargetArchery.orderValue = ++i1
acatDAO.saveAuthCategory(acatTargetArchery)

def acatThrownWeapons = new AuthCategory ()
acatThrownWeapons.description = "Thrown Weapons"
acatThrownWeapons.orderValue = ++i1
acatDAO.saveAuthCategory(acatThrownWeapons)


// Add authorizations
def i = 0
def acDAO = new AuthTypeDAO ()
def acwsh = new AuthType ()
acwsh.code = "AC:WSH"
acwsh.description = "Weapon and Shield"
acwsh.category = acatArmoredCombat
acwsh.martial = false
acwsh.orderValue = ++i
acDAO.saveAuthType(acwsh)

def actw = new AuthType ()
actw.code = "AC:TW"
actw.description = "Two Weapons"
actw.category = acatArmoredCombat
actw.martial = false
actw.orderValue = ++i
acDAO.saveAuthType(actw)

def acgw = new AuthType ()
acgw.code = "AC:GW"
acgw.description = "Great Weapon"
acgw.category = acatArmoredCombat
acgw.martial = false
acgw.orderValue = ++i
acDAO.saveAuthType(acgw)

def acpa = new AuthType ()
acpa.code = "AC:PA"
acpa.description = "Polearm"
acpa.category = acatArmoredCombat
acpa.martial = false
acpa.orderValue = ++i
acDAO.saveAuthType(acpa)

def acsp = new AuthType ()
acsp.code = "AC:SP"
acsp.description = "Spear"
acsp.category = acatArmoredCombat
acsp.martial = false
acsp.orderValue = ++i
acDAO.saveAuthType(acsp)

def acca = new AuthType ()
acca.code = "AC:CA"
acca.description = "Combat Archery"
acca.category = acatArmoredCombat
acca.martial = false
acca.orderValue = ++i
acDAO.saveAuthType(acca)

def acse = new AuthType ()
acse.code = "AC:SE"
acse.description = "Siege Engineer"
acse.category = acatArmoredCombat
acse.martial = false
acse.orderValue = ++i
acDAO.saveAuthType(acse)

def acmarshal = new AuthType ()
acmarshal.code = "AC:Marshal"
acmarshal.description = "Armored Combat Marshal"
acmarshal.category = acatArmoredCombat
acmarshal.martial = true
acmarshal.orderValue = ++i
acDAO.saveAuthType(acmarshal)

def camarshal = new AuthType ()
camarshal.code = "CA:Marshal"
camarshal.description = "Combat Archery Marshal"
camarshal.category = acatCombatArchery
camarshal.martial = true
camarshal.orderValue = ++i
acDAO.saveAuthType(camarshal)

def semarshal = new AuthType ()
semarshal.code = "SE:Marshal"
semarshal.description = "Siege Marshal"
semarshal.category = acatSiege
semarshal.martial = true
semarshal.orderValue = ++i
acDAO.saveAuthType(semarshal)

def rpsr = new AuthType ()
rpsr.code = "RP:SR"
rpsr.description = "Single Rapier"
rpsr.category = acatRapier
rpsr.martial = false
rpsr.orderValue = ++i
acDAO.saveAuthType(rpsr)

def rpdg = new AuthType ()
rpdg.code = "RP:DG"
rpdg.description = "Dagger"
rpdg.category = acatRapier
rpdg.martial = false
rpdg.orderValue = ++i
acDAO.saveAuthType(rpdg)

def rppd = new AuthType ()
rppd.code = "RP:PD"
rppd.description = "Parry Device"
rppd.category = acatRapier
rppd.martial = false
rppd.orderValue = ++i
acDAO.saveAuthType(rppd)

def rpcs = new AuthType ()
rpcs.code = "RP:CS"
rpcs.description = "Case"
rpcs.category = acatRapier
rpcs.martial = false
rpcs.orderValue = ++i
acDAO.saveAuthType(rpcs)

def rpep = new AuthType ()
rpep.code = "RP:EP"
rpep.description = "Epee"
rpep.category = acatRapier
rpep.martial = false
rpep.orderValue = ++i
acDAO.saveAuthType(rpep)

def rpct = new AuthType ()
rpct.code = "RP:CT"
rpct.description = "Cut and Thrust"
rpct.category = acatRapier
rpct.martial = false
rpct.orderValue = ++i
acDAO.saveAuthType(rpct)

def rpMarshal = new AuthType ()
rpMarshal.code = "RP:Marshal"
rpMarshal.description = "Rapier Marshal"
rpMarshal.category = acatRapier
rpMarshal.martial = true
rpMarshal.orderValue = ++i
acDAO.saveAuthType(rpMarshal)

def ctMarshal = new AuthType ()
ctMarshal.code = "CT:Marshal"
ctMarshal.description = "Cut and Thrust Marshal"
ctMarshal.category = acatRapier
ctMarshal.martial = true
ctMarshal.orderValue = ++i
acDAO.saveAuthType(ctMarshal)

def ytd1 = new AuthType ()
ytd1.code = "YT:D1"
ytd1.description = "Youth Div 1,2"
ytd1.category = acatYouth
ytd1.martial = false
ytd1.orderValue = ++i
acDAO.saveAuthType(ytd1)

def ytd3 = new AuthType ()
ytd3.code = "YT:D3"
ytd3.description = "Youth Div 3"
ytd3.category = acatYouth
ytd3.martial = false
ytd3.orderValue = ++i
acDAO.saveAuthType(ytd3)

def ytmarshal = new AuthType ()
ytmarshal.code = "YT:Marshal"
ytmarshal.description = "Youth Marshal"
ytmarshal.category = acatYouth
ytmarshal.martial = true
ytmarshal.orderValue = ++i
acDAO.saveAuthType(ytmarshal)

def eqgr = new AuthType ()
eqgr.code = "EQ:GR"
eqgr.description = "General Riding"
eqgr.category = acatEquestrian
eqgr.martial = false
eqgr.orderValue = ++i
acDAO.saveAuthType(eqgr)

def eqmg = new AuthType ()
eqmg.code = "EQ:MG"
eqmg.description = "Mounted Game"
eqmg.category = acatEquestrian
eqmg.martial = false
eqmg.orderValue = ++i
acDAO.saveAuthType(eqmg)

def eqac = new AuthType ()
eqac.code = "EQ:AC"
eqac.description = "Armored Combat"
eqac.category = acatEquestrian
eqac.martial = false
eqac.orderValue = ++i
acDAO.saveAuthType(eqac)

def eqcc = new AuthType ()
eqcc.code = "EQ:CC"
eqcc.description = "Crest Combat"
eqcc.category = acatEquestrian
eqcc.martial = false
eqcc.orderValue = ++i
acDAO.saveAuthType(eqcc)

def eqdr = new AuthType ()
eqdr.code = "EQ:DR"
eqdr.description = "Driving"
eqdr.category = acatEquestrian
eqdr.martial = false
eqdr.orderValue = ++i
acDAO.saveAuthType(eqdr)

def eqma = new AuthType ()
eqma.code = "EQ:MA"
eqma.description = "Mounted Archery"
eqma.category = acatEquestrian
eqma.martial = false
eqma.orderValue = ++i
acDAO.saveAuthType(eqma)

def eqfj = new AuthType ()
eqfj.code = "EQ:FJ"
eqfj.description = "Lgt Foam Joust"
eqfj.category = acatEquestrian
eqfj.martial = false
eqfj.orderValue = ++i
acDAO.saveAuthType(eqfj)

def eqmarshal = new AuthType ()
eqmarshal.code = "EQ:Marshal"
eqmarshal.description = "Equestrian Marshal"
eqmarshal.category = acatEquestrian
eqmarshal.martial = true
eqmarshal.orderValue = ++i
acDAO.saveAuthType(eqmarshal)

def armarshal = new AuthType ()
armarshal.code = "AR:Marshal"
armarshal.description = "Archery Marshal"
armarshal.category = acatTargetArchery
armarshal.martial = true
armarshal.orderValue = ++i
acDAO.saveAuthType(armarshal)

def twmarshal = new AuthType ()
twmarshal.code = "TW:Marshal"
twmarshal.description = "Thrown Weapons Marshal"
twmarshal.category = acatThrownWeapons
twmarshal.martial = true
twmarshal.orderValue = ++i
acDAO.saveAuthType(twmarshal)


def json = """
"""

namespace.of("system") {
	def name = "middle.validStart"

	Entity sysTable = new Entity("properties")
	sysTable.name = name
	sysTable.property = "06/16/2012"

	sysTable.save()

	name = "middle.validEnd"

	sysTable = new Entity("properties")
	sysTable.name = name
	sysTable.property = "08/31/2012"

	sysTable.save()

	sysTable = new Entity("properties")
	sysTable.name = "middle.earlmarshal.email"
	sysTable.property = "earlmarshal@test.com"

	sysTable.save()

	sysTable = new Entity("properties")
	sysTable.name = "middle.calonsteel.email"
	sysTable.property = "calonsteel@test.com"

	sysTable.save()

	sysTable = new Entity("properties")
	sysTable.name = "middle.central.email"
	sysTable.property = "centraldeputy@test.com"

	sysTable.save()

	sysTable = new Entity("properties")
	sysTable.name = "middle.from.email"
	sysTable.property = "from@test.com"

	sysTable.save()
}

// add users
def fighter = new Entity("Fighter")
fighter.scaName = "Sir Cardmarshal"
fighter.scaMemberNo = "22222"
fighter.modernName = "Bob Somebody"
fighter.googleId = "test@example.com"
fighter.scaGroup = scaGroupKey
fighter.role = UserRoles.CARD_MARSHAL.toString()
fighter.status = "ACTIVE"
fighter.lastUpdated = new Date();

fighter.save()

def authEntity = new Entity("Authorization", fighter.key);
authEntity.authType = acwsh.key
authEntity.date = new Date()
authEntity.save()

authEntity = new Entity("Authorization", fighter.key);
authEntity.authType = actw.key
authEntity.date = new Date()
authEntity.save()

def addressEntity = new Entity("Address", fighter.key)
addressEntity.address1 = "123 Coast Street"
addressEntity.city = "Coast City"
addressEntity.postalCode = "123654"
addressEntity.state = "Coast State"
addressEntity.type = "Home"
addressEntity.save()

def emailEntity = new Entity("Email", fighter.key)
emailEntity.emailAddress = "text@example.com"
emailEntity.type = "Home"
emailEntity.save()

def fighter2 = new Entity("Fighter")
fighter2.scaName = "Lord Fencer"
fighter2.scaMemberNo = "22222"
fighter2.modernName = "Bob Cutandthrust"
fighter2.googleId = "ct@example.com"
fighter2.scaGroup = scaGroupKey
fighter2.role = UserRoles.USER.toString()
fighter2.status = "ACTIVE"
fighter2.lastUpdated = new Date();

fighter2.save()

authEntity = new Entity("Authorization", fighter2.key);
authEntity.authType = rpct.key
authEntity.date = new Date()
authEntity.save()

addressEntity = new Entity("Address", fighter2.key)
addressEntity.address1 = "345 Here"
addressEntity.city = "Somewhere City"
addressEntity.postalCode = "123654"
addressEntity.state = "Coast State"
addressEntity.type = "Home"
addressEntity.save()

emailEntity = new Entity("Email", fighter2.key)
emailEntity.emailAddress = "ct@example.com"
emailEntity.type = "Home"
emailEntity.save()

def fighter3 = new Entity("Fighter")
fighter3.scaName = "Diccon de Reinport"
fighter3.scaMemberNo = "34722"
fighter3.membershipExpires = new Date(115, 7, 31)
fighter3.modernName = "Kevin L Carlen"
fighter3.dateOfBirth = new Date(66, 4, 2)
fighter3.googleId = "kcarlen@insight.rr.com"
fighter3.scaGroup = mugmortGroup.key
fighter3.role = UserRoles.CARD_MARSHAL.toString()
fighter3.status = "ACTIVE"
fighter3.lastUpdated = new Date();

fighter3.save()

authEntity = new Entity("Authorization", fighter3.key);
authEntity.authType = acse.key
authEntity.date = new Date()
authEntity.save()

authEntity = new Entity("Authorization", fighter3.key);
authEntity.authType = semarshal.key
authEntity.date = new Date()
authEntity.save()

authEntity = new Entity("Authorization", fighter3.key);
authEntity.authType = armarshal.key
authEntity.date = new Date()
authEntity.save()

addressEntity = new Entity("Address", fighter3.key)
addressEntity.address1 = "7243 Kirkdale Dr"
addressEntity.city = "Blacklick"
addressEntity.postalCode = "43004"
addressEntity.state = "OH"
addressEntity.type = "Home"
addressEntity.save()

emailEntity = new Entity("Email", fighter3.key)
emailEntity.emailAddress = "kcarlen@insight.rr.com"
emailEntity.type = "Home"
emailEntity.save()

def phoneEntity = new Entity("Phone", fighter3.key)
phoneEntity.phoneNumber = "6148644361"
phoneEntity.type = "Home"
phoneEntity.save()

forward "/StoreDatabase.groovy"